<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
      <div style="padding-top: 1rem;"></div>
      <FormPanel ref="formPanel" :list="formList1" :cols="3" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
      <div style="padding-top: 1rem;"></div>
      <div
        :style="{
          position: 'absolute',
          left: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <multiuse-button type="primary" @click="saveDialog">保 存</multiuse-button>
        <multiuse-button @click="closeDialog">关 闭</multiuse-button>
      </div>
    </Spin>
  </div>
</template>
<script>
import { getAppId} from '@/assets/js/auth';
import {dictionary} from'@/utils/dictMixin';
import { selectById, editSave } from '@/api/graphic/carModelSettings/index.js';
export default {
    props: ['rowData'],
  mixins: [dictionary],
  data() {
    return {
      loading: false,
      dataList1: [],
      visible: false,
      selectedRows: [], //选中系统
      formList1: this.createFormList1(),
      saveData: null,
      newVar: {}
    };
  },
  created() {
  },
 mounted(){
    this.getModel()
  },
  methods: {
    formChangeHandle(val) {
      // console.log(val);
      this.saveData = val;
    },
   async getModel() {
     this.loading = true;
     let newVar = await selectById({modelId: this.rowData.modelId});
     // console.log(newVar)
     this.formList1.forEach(x => {
       // console.log(this.rowData);
       x.initialValue = newVar.data[x.fieldName];
     });
     this.newVar = newVar.data;
     this.loading = false;
   },
    //保存
    saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData !== null) {
        this.loading = true;
        this.rowData.modelCode=this.saveData.modelCode
        this.rowData.modelName=this.saveData.modelName
        // console.log(this.rowData)
        editSave(this.rowData.modelId,this.rowData).then((res)=>{
          if (res.resultCode === 200) {
              // console.log(res)
              this.loading = false;
              this.$emit('save');
              return this.$notify.success({title: '提示信息', message: '保存成功'});
            } else {
              this.loading = false;
              this.$notify.error({title: '提示信息', message: res.errMsg || '保存失败!'});
            }
        });
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close', {visible: false, data: this.selectedRows, type: 'close'});
    },
    createFormList1() {
      return [
        {
          type: 'INPUT',
          label: '车型代码',
          fieldName: 'modelCode',
          placeholder: '请输入车型代码...',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '车型名称',
          fieldName: 'modelName',
          placeholder: '请输入车型名称...',
          rules: [{ required: true, message: '请输入系统名称...', trigger: 'blur' },{ max: 20, message: '长度不能大于20个字符', trigger: 'blur' }],
        }
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
